;; math/series.scm - (c) rohan drape, 2000-2005

;; Evaluate to the sequence of intervals between the elements of the
;; series `s'.  This is Robert Morris's INT procedure, and Open Music's
;; 'd->dx' procedure.

(define (d->dx s)
  (unfold (lambda (l) (null? (cdr l)))
	  (lambda (l) (- (cadr l) (car l)))
	  cdr
	  s))

;; Variant that considers the interval from the first to last element.

(define (d->dx* s) (d->dx (append s (list (car s)))))

;; Evaluates to a series the first element being `n', and subsequent
;; elements summing the previous element with the interval from the
;; interval series `i'.  This is Open Music's 'dx->d' procedure.

(define (dx->d n i)
  (if (null? i)
      (list n)
      (cons n (dx->d (+ (car i) n) (cdr i)))))

